package server.commonData;

import java.util.Collection;

import javax.sound.midi.MidiDevice.Info;

import server.ServerConfigCache;
import server.business.chat.config.InformationConfig;
import server.messageId.S2CMessageId;
import server.msgBean.ChatMessage.InformationRes;

import com.core.initialize.Message;

/**
 * 信息广播
 * @author King
 *
 */
public class Information
{
	
	private InformationRes.Builder res = InformationRes.newBuilder();
	
	private int id;
	
	private Information(){}
	
	/**
	 * 获得一个information对象
	 * 自己new为以后重用对象 优化gc
	 * @return
	 */
	public static Information newInformation(int id)
	{
		Information info = new Information();
		info.id = id;
		return info;
	}

	/**加入参数**/
	public void pushPar(Object... pars)
	{
		for(Object par:pars)
		{
			res.addPar(par.toString());
		}
	}
	/**加入参数**/
	public void pushPar(Collection<String> pars)
	{
		res.addAllPar(pars);
	}
	
	/**转成message对象**/
	public Message toMessage()
	{
		InformationConfig config = getConfig(this.id);
		Message msg = Message.newMessage();
		res.setContent(config.content);
		res.setLoc(config.loc);
		msg.setModuleAction(S2CMessageId.Login.MODULE_ID, S2CMessageId.Login.INFORMATION_RES);
		msg.setBody(res);
		return msg;
	}

	public static InformationConfig getConfig(int id)
	{
		return ServerConfigCache.informationMap.get(id);
	}
	
}

